<!--
* description: 预约容量维护
* author: shensai
* createdDate:2021-1-28
-->
<template>
  <section class="editSetBelowAdd">
    <el-dialog
      v-dialogDrag
      :visible.sync="curPopupsVisible"
      :title="textMap[popupsState]"
      :append-to-body="true"
      width="70%"
      :close-on-click-modal="false"
      @close="closeEdit"
    >
      <dialogHeader
        slot="title"
        :title="titleName"
        :style-type="$store.state.app.dialogType"
      />

      <div class="app-container app-container-table">
        <one-table-template
          ref="multipleTable"
          :dynamic-table-cols="tableCols"
          :dynamic-buttons="tableButtons"
          :dynamic-components="tableComponents"
          :dynamic-api-config="apiConfig"
          :dynamic-form-fields="formField"
          :dynamic-is-show-select="false"
          :dynamic-is-show-more-btn="true"
          :dynamic-table-defult-height="300"
          :is-show-pagination="false"
        />
      </div>
    </el-dialog>
  </section>
</template>
<script>
import OneTableTemplate from "@/components/templates/oneTable";
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { custApi } from "@/api/se/customerManagement.js";

export default {
  components: {
    dialogHeader: () => import("@/components/dialogHeader"),
    OneTableTemplate,
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  props: {
    // 弹出是否显示
    popupsVisible: { type: Boolean, default: false },
    customObj: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },

  data() {
    const viewPageCode = "belowOrd-Edit";
    return {
      titleName: "预约容量维护",
      apiConfig: custApi.shortageAuditQuery,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey3",
          type: "primary",
          size: "small",
          // name: "query",
          clickEvent: () =>
            this.$nextTick(() => {
              this.queryTable(1);
            }),
          text: this.$t("sys.button.query"),
          fuzzySearch: true,
        },
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          // name: "preservation",
          clickEvent: () => this.save(),
          text: this.$t("sys.button.save"),
        },
        {
          compKey: "btnKey2",
          size: "small",
          // name: "cancel",
          // icon: "iconfont icon-cancel",
          clickEvent: () => this.closeEdit(1),
          text: this.$t("sys.button.cancel"),
        },
      ],
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
              {
                compKey: "compKey1",
                labelName: "预约开始日期：",
                codeField: "appointmentStartDate",
                component: () =>
                  import("@/components/org/datePicker/datePicker.vue"),
                type: "datePicker",
                isMust: true,
              },
              {
                compKey: "compKey2",
                labelName: "预约结束日期：",
                codeField: "appointmentEndDate",
                component: () =>
                  import("@/components/org/datePicker/datePicker.vue"),
                type: "datePicker",
                dateType: "date",
                isMust: true,
              },
              //    {
              //   compKey: 'compKey2',
              //   labelName: '预约容量：',
              //   codeField: 'chargeMen',
              //   component: () => import('@/components/org/commonInput'),
              //   type: 'inputText',
              //   isMul: false,
              //   isMust: true
              // },
            ],

      tableCols: [
        {
          prop: "enableDate",
          label: "日期",
        },
        {
          prop: "dlrCode",
          label: "门店编码",
        },
        {
          prop: "timeQuantum1",
          label: "0:00-1:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey2",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum1",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[0-9]*[1-9][0-9]*$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum2",
          label: "1:00-2:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey2",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum2",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[0-9]*[1-9][0-9]*$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum3",
          label: "2:00-3:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey2",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum3",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[0-9]*[1-9][0-9]*$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum4",
          label: "3:00-4:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey2",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum4",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[0-9]*[1-9][0-9]*$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum5",
          label: "4:00-5:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey2",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum5",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[0-9]*[1-9][0-9]*$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum6",
          label: "5:00-6:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey2",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum6",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[0-9]*[1-9][0-9]*$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum7",
          label: "6:00-7:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey2",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum7",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[0-9]*[1-9][0-9]*$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum8",
          label: "7:00-8:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey2",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum8",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[0-9]*[1-9][0-9]*$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
      
        {
          prop: "timeQuantum9",
          label: "8:00-9:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey2",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum9",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[0-9]*[1-9][0-9]*$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum10",
          label: "9:00-10:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey3",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum10",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum11",
          label: "10:00-11:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey4",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum11",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum12",
          label: "11:00-12:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey5",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum12",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum13",
          label: "12:00-13:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey6",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum13",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum14",
          label: "13:00-14:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey7",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum14",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum15",
          label: "14:00-15:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey8",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum15",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum16",
          label: "15:00-16:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey9",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum16",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum17",
          label: "16:00-17:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey10",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum17",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
        {
          prop: "timeQuantum18",
          label: "17:00-18:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey11",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum18",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
         {
          prop: "timeQuantum19",
          label: "18:00-19:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey11",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum19",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
         {
          prop: "timeQuantum20",
          label: "19:00-20:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey11",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum20",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
         {
          prop: "timeQuantum21",
          label: "20:00-21:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey11",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum21",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
         {
          prop: "timeQuantum22",
          label: "21:00-22:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey11",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum22",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
         {
          prop: "timeQuantum23",
          label: "22:00-23:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey11",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum23",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
         {
          prop: "timeQuantum24",
          label: "23:00-24:00",
          isComponent: true,
          comps: [
            {
              compKey: "propKey11",
              // clickEvent: index => this.sendCode(this.codeField, 'timeQuantum9'),
              component: () =>
                import("@/components/org/commonInput/numberInput"),
              codeField: "timeQuantum24",
              step: 1,
              type: "inputText",
              validrule: {
                isformat: /^[+]{0,1}(\d+)$/,
                min: 0,
                max: 100000000,
              },
              dataToObject: {
                min: 0,
                max: 100000000,
              },
              isMust: true,
            },
          ],
        },
      ],
      formField: {
        dlrCode: "",
        enableDate: "",
        appointmentStartDate: "",
        appointmentEndDate: "",
      },
      // 标题
      textMap: {
        add: "预约容量设置",
      },
    };
  },

  mounted() {
    this.$nextTick(() => {
      this.queryTable(1);
    });
  },

  methods: {
    // 保存编辑
    save() {
      const queryObj = {
        // 保存mutation
        type: "mutation",
        // api配置
        apiConfig: custApi.shortageAuditEdit,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: { list: this.$refs.multipleTable.list },
      };
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj);
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then((response) => {
        if (response.result === "1") {
          this.$message({
            message: "保存成功",
            type: "success",
            duration: 2000,
          });
          this.closeEdit();
          this.$nextTick(() => {
            this.$parent.queryTable(1);
          });
          this.closeEdit();
        } else {
          // 保存失败
          this.$message({
            message: "保存失败:" + response.msg,
            type: "warn",
            duration: 2000,
          });
        }
      });
    },

    closeEdit() {
      this.$emit("close");
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/#datePicker i.el-input__icon.el-icon-date:before {
  position: relative;
  right: 30px;
}
</style>